using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class Templates_ArticleSummary : Acms.AcmsControls.BaseTemplateControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void OnPreRender(EventArgs e)
    {
        Acms.WebControls.AcmsDataListItem item = FindAcmsDataListItem(this.NamingContainer);
        if (item != null && item.AjaxPanel != null)
        {
            rsProgress.AssociatedUpdatePanelId = item.AjaxPanel.ID;
        }
        base.OnPreRender(e);
    }

    private Acms.WebControls.AcmsDataListItem FindAcmsDataListItem(Control control)
    {
        if (control == null)
        {
            return null;
        }
        else if (control is Acms.WebControls.AcmsDataListItem)
        {
            return control as Acms.WebControls.AcmsDataListItem;
        }
        else
        {
            return FindAcmsDataListItem(control.Parent);
        }
    }

    public string HighlightText
    {
        get { return ViewState["HighlightText"] as string ; }
        set { ViewState["HighlightText"] = value; }
    }

    public string Highlight(string text)
    {
        if (text != null && HighlightText != null)
        {
            // Setup the regular expression and add the Or operator.
            Regex regExp = new Regex(string.Concat("\\b", HighlightText.Replace(" ", "|").Trim(), "\\b"), RegexOptions.IgnoreCase);
            // Highlight keywords by calling the delegate each time a keyword is found.
            return regExp.Replace(text, new MatchEvaluator(ReplaceKeyWords));
        }
        else
        {
            return text;
        }
    }

    public string ReplaceKeyWords(Match m)
    {

        return "<span class=\"searchHighlight\">" + m.Value + "</span>";

    }
}
